﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RayDen.Library.Core;
using RayDen.Library.Core.Primitives;

namespace RayDen.MegaRay.Core
{
    public struct RayRecord : IRay
    {
        public Point Position;
        public float Phi, Theta, Tmin, Tmax;
        public uint ID;

        public Vector Direction
        {
            get
            {
                return MathLab.SphericalDirection(MathLab.Sin(Theta), MathLab.Cos(Theta), Phi);
            }
            set
            {
                var dir = value.Normalize();
                Phi = MathLab.SphericalPhi(ref dir);
                Theta = MathLab.SphericalTheta(ref dir);
            }
        }

        public Point Origin
        {
            get { return this.Position; }
        }

        public Vector InvDirection
        {
            get { return 1f / Direction; }
        }

        public float Min
        {
            get { return this.Tmin; }
        }

        public float Max
        {
            get { return this.Tmax; }
        }

        public Point Point(float distance)
        {
            return Position + Direction*distance;
        }

        public void SetSegment(float min, float max)
        {
            this.Tmin = min;
            this.Tmax = max;
        }
    }
}
